<?php
/**
 * Created By Project
 * Author: 陈东
 * Copyright：陈东
 * Source Code：陈东
 * Explain：I shall not authorize for any other commercial purposes, law breakers must be prosecuted.
 */
namespace Selfhelp\Controller;
use Think\Controller;

class RegController extends Controller {

	/*
	 * 注册登录
	 */
    public function index(){
		if(!isset($_COOKIE['newissubscribe'])){
			header('Location:http://pay.hrtv.cn/Hrmservercenter/Newissubscribe?redirect_url=http://h5.hrtv.cn/Selfhelp/Reg/index');
		}else if($_COOKIE['newissubscribe']==0){
			header('Location:http://h5.hrtv.cn/Selfhelp/Index/guanzhu');
		}else if($_COOKIE['newissubscribe']==1){
			/*获取cookie*/
			$usertoken = $_COOKIE['user_userinfo'];
			if(empty($usertoken)){
				header("Location:http://e.hrtv.cn/ehrtv/Login/index?url=".getURL());
			}else{
				$selfhelp = D(C('TABLE_SELFHELP'));
				$res = $selfhelp->where(array('user_token'=>$usertoken))->count();
				if($res>0){
					header("Location:http://h5.hrtv.cn/Selfhelp/Index/lists");
				}else{
					$this->display();
				}
			}
		}

    }

	/*
	 * 获取session保存的验证码
	 */
	public function getverifynote(){
		$userpass = I('post.userpass');
		if(!empty(session('verftel'))){
			if($userpass==session('verftel')){
				echo 1; //通过
			}else{
				echo 0; //不正确
			}
		}else{
			echo 2;//验证码过期
		}
	}

	/*
	 * 发送手机验证码
	 */
	public function verifynote(){
		$tel = I('post.usertel');
		$fun= new \Org\Util\fun();
		$tmppwd = substr(mt_rand()."000000",0,6);
		$ssmmess = $fun->SendSms($tel,$tmppwd);
		session('verftel',null);
		session('verftel',$tmppwd);
		//echo $tmppwd;
	}

	/*
	 * 手机号检查
	 */
	public function telcheck(){
		$telres = D(C('TABLE_SELFHELP'));
		$tel = I('post.usertel');
		$num = $telres->where(array('user_tel'=>$tel))->count();
		if($num > 0){
			echo 3;//存在此号码
		}else{
			echo 1;//不存在
		}
	}

	public function notebook(){
		$this->display();
	}

}